package com.mybatisflex.test.controller;


import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.entity.Account;
import com.mybatisflex.test.mapper.AccountMapper;
import static com.mybatisflex.test.entity.table.AccountTableDef.ACCOUNT;
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountMapper accountMapper;

    @GetMapping("/insert")
    public String insert(){
        Account acc =new Account();
        acc.setAge(18);
        acc.setUserName("rico");
        //acc.setBirthday("2023-09-10");
        accountMapper.insert(acc);
        return acc.toString();
}
    @GetMapping("/selectall")
    public String selectAll(){
        List<Account>  accs = accountMapper.selectAll();
        accs.forEach(System.out::println);
        return "accs.size()";
    }

    @GetMapping("/select")
    public String select(){
                QueryWrapper queryWrapper = QueryWrapper.create()
                .select()
                .where(ACCOUNT.AGE.eq(28));
        Account account = accountMapper.selectOneByQuery(queryWrapper);
        System.out.println(account);
        return account.toString();
}
}